# encoding: utf-8
__author__ = 'wwj'
import re
import sys
reload(sys)
sys.setdefaultencoding('utf8')
# sys.path.append("/Users/wwj/Downloads/shangtianjun/girl/girl/dbShell")
from dbshell import dbshell
from datetime import *
from zlib import crc32
import copy
from __future__ import unicode_literals
import youtube_dl

class MyLogger(object):
    def debug(self, msg):
        pass

    def warning(self, msg):
        pass

    def error(self, msg):
        print(msg)





class main(dbshell):
    orderItem = [
            ['seriesId', ''],
            ['directorId', ''],
            ['title', ''],
            ['name', ''],
            ['bwh', ''],
            ['designation', ''],
            ['cateId', ''],
            ['manufacturerId', ''],
            ['bigImg', ''],
            ['type', ''],
            ['series', ''],
            ['director', ''],
            ['cate', ''],
            ['version', ''],
            ['manufacturer', ''],
            ['thumb', ''],
            ['video', ''],
            ['img', ''],
    ]
    mongoTable = "movie"
    mysqlTable = "dmm_av"
    exesize = 500
    def __init__(self,spidername):
        super(main,self).__init__(spidername)

    def clean(self,y):
        data = self.data

    def my_hook(d):
        if d['status'] == 'finished':
            print('Done downloading, now converting ...')

    ydl_opts = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
        'logger': MyLogger(),
        'progress_hooks': [my_hook],
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

    # tmpdata = copy.deepcopy(data)
    # self.datas.append(tmpdata)


if __name__ == '__main__':
    obj = main("dmm")
    obj()
